﻿using AutoMapper;
using B.S.DataBase.SuY.Read.Api.AutoList.Command;
using B.S.DataBase.SuYuan.Domain.Model;
using B.S.DataBase.SuYuan.ErrorCode;
using B.S.DataBase.SuYuan.Infrastructrue.Interface;
using MediatR;

namespace B.S.DataBase.SuY.Read.Api.AutoList.CommandHarder
{
    public class UpdateGoodsCommandHarder : IRequestHandler<UpdateGoodsCommand, ApiReslit<object>>
    {

        private readonly IMapper mapper;
        private readonly IBaseRepository<Goods> repository;

        public UpdateGoodsCommandHarder(IMapper mapper, IBaseRepository<Goods> repository)
        {
            this.mapper = mapper;
            this.repository = repository;
        }

        public Task<ApiReslit<object>> Handle(UpdateGoodsCommand request, CancellationToken cancellationToken)
        {
            ApiReslit<object> reslit = new ApiReslit<object>();
            reslit.Code = ApiEnum.修改成功;
            reslit.Msg = ApiEnum.修改成功.ToString();

            var xi = repository.GetAll().Result.Where(x => x.G_Id == request.G_Id).FirstOrDefault();
            xi.UpdateTime= DateTime.Now;
            xi.CommId= request.CommId;
                xi.G_batch= request.G_batch;
                xi.G_Shelf= request.G_Shelf;
            xi.G_License = request.G_License;
            xi.G_enterprise = request.G_enterprise;
                xi.G_image= request.G_image;


        repository.Update(xi);

            return Task.FromResult(reslit);
        }
    }
}
